using Meebey.SmartIrc4net;

namespace Thunder.Irc.Formatter
{
    /// <summary>
    /// Base class for message formatters 
    /// </summary>
    public abstract class MessageFormatter : IMessageFormatter
    {
        /// <summary>
        /// Gets the resource path to the image
        /// </summary>
        public string ImagePath
        {
            get { return this.GetImagePathCore(); }
        }

        /// <summary>
        /// This method is invoked when the resource image path is being resolved
        /// </summary>
        /// <returns>A string containing the path to the image</returns>
        protected virtual string GetImagePathCore()
        {
            return string.Empty;
        }

        /// <summary>
        /// Gets the current <see cref="FormatManager"/> instance
        /// </summary>
        public FormatManager Manager { get; private set; }

        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public abstract ReceiveType MessageType { get; }

        /// <summary>
        /// This method is invoked when a message should be formatted
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageFormattingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelMessageFormattingEventArgs.Cancel"/> to true</remarks>
        public void Format(CancelMessageFormattingEventArgs args)
        {
            this.FormatCore(args);
        }

        /// <summary>
        /// Initializes the message formatter
        /// </summary>
        /// <param name="manager">The <see cref="FormatManager"/> instance</param>
        public void Initialize(FormatManager manager)
        {
            this.Manager = manager;

            this.InitializeCore();
        }

        /// <summary>
        /// This method is invoked when a message should be formatted
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageFormattingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelMessageFormattingEventArgs.Cancel"/> to true</remarks>
        protected virtual void FormatCore(CancelMessageFormattingEventArgs args)
        {
        }

        /// <summary>
        /// This method in invoked during initialize
        /// </summary>
        protected virtual void InitializeCore()
        {
        }
    }
}